﻿using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BenchmarkDotnetSample.ConsoleApp.Tests
{
    [CoreJob,ClrJob]
    [MemoryDiagnoser]
    public class SingleVsFirstContext
    {
        private List<string> _list = new List<string>();
        private int _size = 100000;
        //private string _tag = "_needle";

        public List<string> needles
        {
            get
            {
                return new List<string> { "startNeedle,middleNeedle,endNeedle" };
            }
        }
        public SingleVsFirstContext()
        {
            Enumerable.Range(0, _size).ToList()
                .ForEach(i => _list.Add(i.ToString()));
            for (int i = 0; i < needles.Count; i++)
            {
                _list.Insert((_size / 2) + i, needles[i]);
            }
        }
        [ParamsSource(nameof(needles))]
        public string Needle { get; set; }
        [Benchmark]
        public void First()
        {
            _list.FirstOrDefault(i => i.Equals(Needle));
        }
        [Benchmark]
        public void Single()
        {
            _list.SingleOrDefault(i => i.Equals(Needle));
        }
    }
}
